<%--
 *  File:    NotesEdit.jsp
 *  @Author: Vector mao
 *  Date:    2/19/2002 13:45
 *
 *  Copyright (C) 2000 - 2002 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  	Category cat = Category.getInstance("jsp.NotesEdit");
  	//init param
  	String strModuleName = "BIEE";
	String privilegeCode = "Z0402,L301";
%>



<%
  	HashMap userInfo = (HashMap)session.getAttribute("userinfo");
%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%int LangNums = ConstantProp.multiLangNumber;%>
<html>

<head>
<title>NotesEdit</title>
<PageFlow:CheckPageFlow pageName="publicationnotesedit"/>
<%@ include file="/inc/InitEdit.inc" %>

<%
	HashMap myhash = null;

	Vector newpictures = null;
	Vector content = null;
	
	myhash = (HashMap)pageContext.getAttribute("pubnotesinfo");
	newpictures = (Vector)pageContext.getAttribute("newpictures");
	content = (Vector)pageContext.getAttribute("content");

  if (newpictures == null)
    newpictures = new Vector();
  if (content == null)
    content = new Vector();

  String notesid = new String("");
  String title = new String("");
  String ispublic = "";
  String begindate = "";
  String enddate = "";
  String userid =  ""+userInfo.get("userid");


 	Integer nContentId0 = null;
  Integer nContentId1 = null;
  Integer nContentId2 = null;
  Integer nContentId3 = null;
  String titlecn = "";
  String titleen = "";
  String contentcn = "";
  String contenten = "";

  int isnewflag = -1;

	if(myhash == null)
	{
  	myhash = new HashMap();
  	
	  GregorianCalendar aDate = new GregorianCalendar();
	  String year = ""+aDate.get(Calendar.YEAR);
	  String month = aDate.get(Calendar.MONTH)>8?""+(aDate.get(Calendar.MONTH)+1):"0"+(aDate.get(Calendar.MONTH)+1);
	  String day = aDate.get(Calendar.DAY_OF_MONTH)>9?""+aDate.get(Calendar.DAY_OF_MONTH):"0"+aDate.get(Calendar.DAY_OF_MONTH);
	}
	else
	{
	  if ((myhash.get("notesid"))!=null)
	  {
	    notesid = (myhash.get("notesid")).toString();
	    userid = (myhash.get("userid")==null ? "" : (myhash.get("userid")).toString());
	    isnewflag = 1;
	  }
    ispublic = (myhash.get("ispublic")==null ? "N" : (myhash.get("ispublic")).toString());
    enddate = (myhash.get("enddate")==null ? "" : (myhash.get("enddate")).toString());
	}
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../css/<%= strLanguageCode %>/script.js">
</script>
<script language="JavaScript" src="../js/FuncLib.js">
</script>
<script language="JavaScript" src="../js/ScriptLib.js">
</script>
<script>
function page_done()
{    
	 if(getLength(cform.title.value)>128)
	 {
      alert("<%= message.getMessageDesc("LENGTH_MUST_LESSTHAN",label.getLabelName("L_TitleCN",false),"128") %>");
	    return;
	 }
	  
	  if(!isNumber(cform.defaultexpiredays.value))
	  {
      alert("<%= message.getMessageDesc("VALUE_MUST_BE_POS_INT",label.getLabelName("L_EffectiveDay",false)) %>");
	    return;
	  }
	  if(!checkNull(document.cform)) return;
    var opts = cform.picturenames.options;
    var hiddenpname = "";
    if (opts!=null)
    for (var i = 0 ; i<opts.length;i++)
      hiddenpname += "<input type=hidden name=newpictures value="+opts[i].value +">";
    hide.innerHTML = hiddenpname;
    
    MLCSTransform(document.cform);
    emptyToNull(document.cform);  
  
  	document.cform.actionname.value = "done";
  	document.cform.target = "_parent";
  	isRunning = true;
  	document.cform.submit();
}
function choosepublic()
{
 if (document.cform.ispublic.value == "Y")
 {
   document.cform.ispublic.value = "N";
 }else
 {
   document.cform.ispublic.value = "Y";
 }
}
   
function deloption()
{
    var opts = cform.picturenames.options;
    if (opts!=null)
    for (var i = opts.length-1 ; i>=0;i--)
    {
      if (opts[i].selected == true)
        opts.remove (i);
    }

}
function page_operate(operand)
{
    if (operand=='addpic')
    {
      var pname = ""+cform.picture.value;
      if (pname=="")
        return;
     /* if(!allIsEnglish(cform.picture.value))
      {
        alert("<%= message.getMessageDesc("MUST_BE_EN",label.getLabelName("L_Maccessory",false) + label.getLabelName("L_Name",false)) %>");        
        return;
      }  
      if(!allIsEnglish(cform.picturename.value))
      {
        alert("<%= message.getMessageDesc("MUST_BE_EN",label.getLabelName("L_Maccessory",false) + label.getLabelName("L_Name",false)) %>");
        return;
      }  
      */
       var re = /.txt$|.csv$|.doc$|.docx$|.xls$|.xlsx$|.vsd$|.pdf$|.ppt$|.pptx$|.zip$|.rar$|.bmp$|.jpg$|.tiff$|.gif$|.pcx$|.tga$|.exif$|.fpx$|.svg$|.psd$|.cdr$|.pcd$|.dxf$|.ufo$|.eps$|.ai$|.raw$/ig;
      if(pname.toUpperCase().match(re) == null)
      {
        alert("<%= message.getMessageDesc("ILLEGAL_FORMAT",label.getLabelName("L_Maccessory",false)) %>");
        return;
      }  
      if (pname.indexOf("\\")!=-1)
        pname = pname.substring(pname.lastIndexOf("\\")+1,pname.length);
      if (cform.picturename.value=="")
        cform.picturename.value = pname;
      if(cform.picturename.value.toUpperCase().match(re) == null)
      {
        if(pname.lastIndexOf(".") != -1)
          cform.picturename.value += pname.substring(pname.lastIndexOf("."));
        <%--[SCRIPT]  alert("<#%= message.getMessageDesc("ILLEGAL_FORMAT",label.getLabelName("L_Picture",false)) %#>");  [SCRIPT]--%>
        <%--[SCRIPT]  return;  [SCRIPT]--%>
      }  

      if (getLength(cform.picturename.value)>40)
      {
		    alert("<%= message.getMessageDesc("LENGTH_MUST_LESSTHAN", label.getLabelName("L_Name",false),"40") %>" );
		    return;
      }
       if(hasSpace(cform.picturename.value)){
      	alert("<%= message.getMessageDesc("AttachmentName_CANNOT_HAS_SPACE") %>");
      	return;
      }
     
    }

  	cform.actionname.value = operand;
  	cform.target = "_self";
  	isRunning = true;
  	cform.submit();

}
var popwindow;
function page_mulilang(name,label,num,need)
{
  var notesid=document.cform.notesid.value;
  if(popwindow!=null)
    popwindow.close();
  var strurl="../common/Lang.jsp?<%= OvalTools.randomURL() %>&form=cform&module=BIEE&mlctype="+label+"&nativelanguage="+need+"&schema=ovnoteslang&entityid="+notesid+"&entitytype="+name+"&contentid=noteslangid&colindex="+num;
  var strStatus= "height=250, width=250,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no";
  popwindow=window.open(strurl, "newwindow",strStatus);
}
</script>
</head>
<body>

	<%--------------------------------------  hidden form variant   --%>
	<form name="cform" method="post" action="../Dispatcher" ENCTYPE="multipart/form-data">
    <input type="hidden" name="pagename" value="publicationnotesedit">
    <input type="hidden" name="actionname">
    <input type="hidden" name="languagecode" value="<%= strLanguageCode %>">

    <input type="hidden" name="notesid" value="<%=JspHelper.filterNull( notesid )%>">
    <input type="hidden" name="status" value="10">
	  <input type="hidden" name="grade" value="1">
    <input type="hidden" name="fromuserid" value="<%=JspHelper.filterNull( userid )%>">
	  <input type="hidden" name="subjectcode" value="202">
	  <%if ((myhash.get("notesid"))==null){%>
	  <input type="hidden" name="begindate" value="<%=OvalTools.getDate("yyyy-MM-dd HH:mm:ss")%>">
	  <%} else {%>
	  <input type="hidden" name="begindate" value="<%= OvalTools.dateToString((java.util.Date)myhash.get("begindate"), "yyyy-MM-dd HH:mm:ss")%>">
      <%}%>
   	<input type="hidden" name="entityid" value="<%=JspHelper.filterNull( notesid )%>">
    <input type="hidden" name="entitytype" value="N">
   	<input type="hidden" name="entityid0" value="<%=JspHelper.filterNull( notesid )%>">
   	<input type="hidden" name="entityid1" value="<%=JspHelper.filterNull( notesid )%>">
   	<input type="hidden" name="entityid2" value="<%=JspHelper.filterNull( notesid )%>">
   	<input type="hidden" name="entityid3" value="<%=JspHelper.filterNull( notesid )%>">
   	<%if (newpictures.size()>4)
   	for (int i=4;i<newpictures.size();i++){
   	%>
   	<input type="hidden" name="entityid<%=JspHelper.filterNull(i)%>" value="<%=JspHelper.filterNull( notesid )%>">
   	<%}%>
   	<%int i=0;%>
    <logic:iterate id="ps" collection="<%= newpictures %>" indexId="orderId">
    <%HashMap psMap = (HashMap)ps;
    if (psMap!=null&&psMap.get("picturename")!=null){
    %>
   	<input type="hidden" name="pictureid<%=JspHelper.filterNull(i)%>" value="<%=JspHelper.filterNull( psMap.get("pictureid") )%>">
   	<input type="hidden" name="picturename<%=JspHelper.filterNull(i)%>" value="<%=JspHelper.filterNull( psMap.get("picturename") )%>">
   	<%++i;}%>
    </logic:iterate>


    <input type="hidden" name="entitytype0" value="NT">
    <input type="hidden" name="entitytype1" value="NT">
    <input type="hidden" name="entitytype2" value="NC">
    <input type="hidden" name="entitytype3" value="NC">
    <input type="hidden" name="numrows" value="<%=LangNums%>">
    <input type="hidden" name = "ispublic" value = "Y">
<table width="100%" cellspacing="0" border="0" cellpadding="0">
  <tr>
    <td>
      <table width="100%" cellspacing="0" cellpadding="0">
        <tr>
          <td colspan="2" class="summary_top"></td>
        </tr>
        <tr>
          <td colspan="2"><img src="../images/<%= strLanguageCode %>/quote.gif" width="16" height="11">
            <%= label.getLabelName("L_Publication")%><%= label.getLabelName("L_Colon") %></td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td class="summary_top"></td>
  </tr>
  <tr>
    <td>
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
        	<%
          		String strTextTypeCN = "td-text";
          		String strTextTypeEN = "td-text";
          		String strNullCN = "Y";
          		String strNullEN = "Y";
          		if(strLanguageCode.equalsIgnoreCase("cn"))
          		{
            		strTextTypeCN = "need";
            		strNullCN = "N";
            	}
          		if(strLanguageCode.equalsIgnoreCase("en"))
          		{
            		strTextTypeEN = "need";            
            		strNullEN = "N";
            	}
        	%>

        <tr>
          <td class="<%=JspHelper.filterNull( strTextTypeCN )%>" width="90"><%= label.getLabelName("L_TitleCN") %><%= label.getLabelName("L_Colon") %></td>
          <td colspan="3">
            
            <custom:text name="pubnotesinfo" property="title" size="122" module="BIEE" label="L_TitleCN" needMLC="true" isFirstMLC="true"  multiLangType="nt" entityId="notesid" contentId="noteslangid" colIndex="0"/>
	          <a onclick="page_mulilang('nt','L_TitleCN',0,'');"><custom:button type="3" label="L_Ln" imgsrc="ln.gif" border="0"/></a> 
          </td>
        </tr>
        
        <tr>
          <td class="<%=JspHelper.filterNull( strTextTypeCN )%>"><%= label.getLabelName("L_ContentCN") %><%= label.getLabelName("L_Colon") %></td>
          <td colspan="3">
            
            <custom:textarea name="pubnotesinfo" property="content" cols="90" rows="3" module="BIEE" label="L_ContentCN" needMLC="true"  multiLangType="nc" entityId="notesid" contentId="noteslangid" colIndex="0"/>
	          <a onclick="page_mulilang('nc','L_ContentCN',0,'');"><custom:button type="3" label="L_Ln" imgsrc="ln.gif" border="0"/></a> 
          </td>
        </tr>
        

         <tr>
          <td class="td-text" ><%= label.getLabelName("L_EffectiveDay") %><%= label.getLabelName("L_Colon") %></td>
          <td colspan="3">
          <% int defaultexpireday = 7;
             if ( pageContext.getAttribute("defaultexpiredays") instanceof Double)
                 defaultexpireday =  ((Double)pageContext.getAttribute("defaultexpiredays")).intValue();
             else if ( pageContext.getAttribute("defaultexpiredays") instanceof Integer)
                 defaultexpireday =  ((Integer)pageContext.getAttribute("defaultexpiredays")).intValue();
           %>
            <input type=text name="defaultexpiredays" value="<%=JspHelper.filterNull(defaultexpireday)%>" size="20">
          </td>
        </tr>
        <tr>
          <td class="td-text" rowspan="2"><%= label.getLabelName("L_Maccessory") %><%= label.getLabelName("L_Colon") %></td>
          <td width="200" rowspan="2" style="line-height: 50%">
            <select name="picturenames" size="5" multiple>
              <logic:iterate id="ps" collection="<%= newpictures %>" indexId="orderId">
					    <%HashMap psMap = (HashMap)ps;
					    if (psMap!=null&&psMap.get("picturename")!=null){
					    %>
              <option value="<%=JspHelper.filterNull( psMap.get("picturename") )%>"><%=JspHelper.filterNull( psMap.get("picturename") )%></option>
              <%}%>
              </logic:iterate>
            </select>
            <br><br>
            <a onclick="page_operate('delpic')"><custom:button type="1" label="L_Delete" imgsrc="delete.gif" border="0" style="width:60"/></a>
          </td>
          <td colspan="2">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td><%if(isnewflag==1){ %><%= label.getLabelName("L_Name") %><%= label.getLabelName("L_Colon") %>
                  <input type="text" name="picturename" size="10">&nbsp;<%= label.getLabelName("L_Path") %><%= label.getLabelName("L_Colon") %><input type="file" name="picture" size="12">
                </td>
                <td><a onclick="page_operate('addpic')"><custom:button type="1" label="L_Upload" imgsrc="Upload.gif" border="0" style="width:60"/></a>  <%}%>&nbsp;</td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td style="line-height: 150%" class="td-listrom" colspan="2"><%= label.getLabelName("L_Step1") %><br>
            <%= label.getLabelName("L_Step2") %><br>
            <%= label.getLabelName("L_Step3") %><br>
            <%= label.getLabelName("L_Step4") %></td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td class="summary_top"></td>
  </tr>
  <tr>
    <td class="td_center"><a onclick="page_done()"><custom:button type="1" label="L_Finish" imgsrc="finish.gif" border="0" style="width:60"/></a></td>
  </tr>
</table>
</body>
<span id=hide></span>
</form>
<script language="JavaScript">
document.cform.picturename.value = "";
document.cform.picture.value = "";
</script>
</html>


